#include "KoldarCTester.h"

#include "LabelList.h"
#include "memory-tools.h"

/**tests:
 * \li initLabelList();
 * \li addLabelToLabelList();
 * \li printLabelList();
 * \li removeLabelFromLabelList();
 * \li getLabelListSize();
 *
 */
void testLabelList(){

	resetMemoryObservation();

	PlabelList list=initLabelList();

	Plabel id1=initLabel("foo",LABEL_PUBLIC);
	Plabel id2=initLabel("bar",LABEL_PACKAGE);
	Plabel id3=initLabel("xyz",LABEL_PUBLIC);

	addLabelToLabelList(id1,list);
	kct_assertEqualIntMsg("the list has not added id1!",1,getLabelListSize(list));
	addLabelToLabelList(id2,list);
	addLabelToLabelList(id3,list);

	printf("complete list: ");
	printLabelList(stdout,list);
	printf("\n");
	kct_assertEqualIntMsg("the list has not added 3 elements!",3,getLabelListSize(list));

	printf("looking for id2...\n");
	Plabel id2search=findLabelInLabelList(id2,list);
	printf("id2 search pointer value %p\n",id2search);
	kct_assertEqualPtrMsg("id2 has not been found",id2,id2search);

	printf("removing id2...\n");
	removeLabelFromLabelList(id2,list);

	id2search=findLabelInLabelList(id2,list);
	printf("id2 search pointer value %p\n",id2search);

	kct_assertEqualPtrMsg(,"id2 has not been deleted",NULL,id2search);
	kct_assertEqualIntMsg(,"size of list is not 2!",2,getLabelListSize(list));

	printf("list without id2: ");
	printLabelList(stdout,list);
	printf("\n");

	printf("freeing labels...\n");
	freeLabel(id1);
	freeLabel(id2);
	freeLabel(id3);

	kct_assertEqualIntMsg("something inside memory-tools is not right!",sizeof(LabelList),getMemoryAllocated());

	printf("freeing list...\n");
	freeLabelList(list);
}


void main(){

	kct_addTestImproved(testLabelList,true);
	//TODO add more tests here...

	kct_runAllTest(stdout);
}
